package com.hkfn.rfb.rfb.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.hkfn.rfb.R;
import com.hkfn.rfb.common.activity.BaseActivity;
import com.hkfn.rfb.common.adapter.BaseRecyclerAdapter;
import com.hkfn.rfb.rfb.bean.RfbDataModel;

public class RfbDataMonitorSelectItemAdapter extends BaseRecyclerAdapter<RfbDataModel> {

    private BaseActivity baseActivity;

    public RfbDataMonitorSelectItemAdapter(BaseActivity baseActivity) {
        this.baseActivity = baseActivity;
    }

    @Override
    public RecyclerView.ViewHolder onCreate(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(baseActivity).inflate(R.layout.item_data_monitor_select_item, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBind(RecyclerView.ViewHolder viewHolder, int RealPosition, RfbDataModel data) {
        if (viewHolder instanceof MyViewHolder){
            setItemData((MyViewHolder)viewHolder, data);
        }
    }

    private class MyViewHolder extends RecyclerView.ViewHolder{

        private CheckBox cb_item_select;
        private TextView tv_item_name;
        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            initItemView(this, itemView);
        }
    }

    private void initItemView(MyViewHolder myViewHolder, View itemView) {
        myViewHolder.cb_item_select = itemView.findViewById(R.id.cb_item_select);
        myViewHolder.tv_item_name = itemView.findViewById(R.id.tv_item_name);
    }

    private void setItemData(MyViewHolder viewHolder, RfbDataModel data) {
        viewHolder.cb_item_select.setSelected(data.isSelected());
        viewHolder.tv_item_name.setText(data.getDataName());
    }

}
